1   /*
2    * Copyright (c) 2004-2005, University Health Network.  All rights reserved. Distributed under the BSD 
3    * license (see http://opensource.org/licenses/bsd-license.php).
4    *  
5    * Created on 17-Jan-2005
6    */
7   package ca.uhn.cache.proxy.impl;
8   
9   import java.lang.reflect.Method;
10  
11  import ca.uhn.cache.IDataItem;
12  import ca.uhn.cache.IQuery;
13  import ca.uhn.cache.proxy.IDataInspector;
14  import junit.framework.TestCase;
15  
16  /***
17   * Unit tests for AbstractMethodAdapter.  
18   * 
19   * @author <a href="mailto:bryan.tripp@uhn.on.ca">Bryan Tripp</a>
20   * @version $Revision: 1.2 $ updated on $Date: 2005/01/25 22:04:28 $ by $Author: aguevara $
21   */
22  public class AbstractMethodAdapterTest extends TestCase {
23  
24      /***
25       * Constructor for AbstractMethodAdapterTest.
26       * @param theName ...
27       */
28      public AbstractMethodAdapterTest(String theName) {
29          super(theName);
30      }
31  
32      /***
33       * Class under test for void AbstractMethodAdapter(String, Class[], int, IDataInspector)
34       * 
35       * @throws Exception ...
36       */
37      public void testAbstractMethodAdapterStringClassArrayintIDataInspector() throws Exception {
38          Method method = Object.class.getMethod("wait", new Class[]{long.class});            
39          AbstractMethodAdapter adapter 
40              = new MockAdapter(method, 2, new MockInspector());
41          
42          assertEquals(MockInspector.class, adapter.getDataInspector().getClass());
43          assertEquals(2, adapter.getMaxGroups());
44          assertEquals("wait", adapter.getMethodName());
45          assertEquals(1, adapter.getArgTypes().length);
46          assertEquals(long.class, adapter.getArgTypes()[0]);
47      }
48  
49      /***
50       * Class under test for void AbstractMethodAdapter(Method, int, IDataInspector)
51       */
52      public void testAbstractMethodAdapterMethodintIDataInspector() {
53          AbstractMethodAdapter adapter 
54              = new MockAdapter("wait", new Class[]{long.class}, 2, new MockInspector());
55          
56          assertEquals(MockInspector.class, adapter.getDataInspector().getClass());
57          assertEquals(2, adapter.getMaxGroups());
58          assertEquals("wait", adapter.getMethodName());
59          assertEquals(1, adapter.getArgTypes().length);
60          assertEquals(long.class, adapter.getArgTypes()[0]);
61      }
62      
63      /***
64       * Mock. 
65       * 
66       * @author <a href="mailto:bryan.tripp@uhn.on.ca">Bryan Tripp</a>
67       * @version $Revision: 1.2 $ updated on $Date: 2005/01/25 22:04:28 $ by $Author: aguevara $
68       */
69      private static class MockAdapter extends AbstractMethodAdapter {
70  
71          /***
72           * @param theMethodName
73           * @param theArgTypes
74           * @param theMaxGroups
75           * @param theInspector
76           */
77          public MockAdapter(String theMethodName, Class[] theArgTypes,
78                  int theMaxGroups, IDataInspector theInspector) {
79              super(theMethodName, theArgTypes, theMaxGroups, theInspector);
80          }
81  
82          /***
83           * @param theMethod
84           * @param theMaxGroups
85           * @param theInspector
86           */
87          public MockAdapter(Method theMethod, int theMaxGroups, IDataInspector theInspector) {
88              super(theMethod, theMaxGroups, theInspector);
89          }
90  
91          /*** 
92           * @see ca.uhn.cache.proxy.IMethodAdapter#getParamsFromArgs(java.lang.Object[])
93           */
94          public IQuery getParamsFromArgs(Object[] theMethodArgs) {
95              return null;
96          }
97  
98          /*** 
99           * @see ca.uhn.cache.proxy.IMethodAdapter#getArgs(java.lang.Object[], ca.uhn.cache.IQuery)
100          */
101         public Object[] getArgs(Object[] theOriginalArgs, IQuery theQuery) {
102             return null;
103         }
104 
105         /*** 
106          * @see ca.uhn.cache.proxy.IMethodAdapter#includeInResults(java.lang.Object, java.lang.Object[])
107          */
108         public boolean includeInResults(Object theDataItem, Object[] theMethodArgs) {
109             return false;
110         }
111         
112     }
113     
114     /***
115      * Mock. 
116      * 
117      * @author <a href="mailto:bryan.tripp@uhn.on.ca">Bryan Tripp</a>
118      * @version $Revision: 1.2 $ updated on $Date: 2005/01/25 22:04:28 $ by $Author: aguevara $
119      */
120     private static class MockInspector implements IDataInspector { 
121         public IDataItem wrap(Object theDataVaue) {
122             return null;
123         }
124     }
125 
126 }